package net.dopan.pigframe.api.fegin.fallback;

import lombok.extern.slf4j.Slf4j;
import net.dopan.pigframe.api.fegin.OSSServiceApi;
import net.dopan.pigframe.core.base.controller.response.ResponseBean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/***
 * @Package: net.dopan.pigframe.api.fegin.fallback
 * @Title: OSSServiceFallback
 * @Description: OSS服务接口错误回调
 * @author: 刘宽
 * @date: 2018/8/30 17:31
 */
@Slf4j
@Service
@Component
public class OSSServiceFallback implements OSSServiceApi {

    /**
     * 文件上传
     *
     * @param file
     * @return
     */
    @Override
    public ResponseBean<String> upload(@RequestPart("file") MultipartFile file){
        log.error("调用 {} 异常: {}", "file", file.getOriginalFilename());
        return new ResponseBean<>(ResponseBean.FAIL, "OSSServiceFallback调用异常 :" + file.getOriginalFilename(), null);
    }

    /**
     * 文件上传(多)
     *
     * @param file
     * @return
     */
    @Override
    public ResponseBean<List<String>> uploads(@RequestPart("file") MultipartFile[] file){
        log.error("调用 {} 异常: {}", "file:", file.length);
        return new ResponseBean<>(ResponseBean.FAIL, "OSSServiceFallback调用异常 :file number:" + file.length, null);
    }
}
